package com.voilet.interview.open.glide.load.model;

import android.content.Context;
import android.support.annotation.NonNull;

import com.voilet.interview.open.glide.Glide;
import com.voilet.interview.open.glide.Registry;

/**
 * An interface for creating a {@link ModelLoader} for a given model type.
 * <p>
 * <p>The application {@link Context} can be passed in to the constructor of the
 * factory when necessary. It's unsafe to retain {@link android.app.Activity}
 * {@link Context}s in factories. The {@link Context} can be
 * obtained from
 * {@link com.voilet.interview.open.glide.module.LibraryGlideModule#registerComponents(Context, Glide, Registry)}
 * in most cases.
 * 根据给定的类型，创建不同的ModelLoader，因为它会被静态持有，所以不应该维持非应用生命周期的context或者对象。
 *
 * @param <T> The type of the model the {@link com.voilet.interview.open.glide.load.model.ModelLoader}s built by
 *            this factory can handle
 * @param <Y> The type of data the {@link com.voilet.interview.open.glide.load.model.ModelLoader}s built by this
 *            factory can load.
 */
public interface ModelLoaderFactory<T, Y> {

    /**
     * Build a concrete ModelLoader for this model type.
     *
     * @param multiFactory A map of classes to factories that can be used to construct additional
     *                     {@link ModelLoader}s that this factory's {@link ModelLoader} may depend on
     * @return A new {@link ModelLoader}
     */
    @NonNull
    ModelLoader<T, Y> build(@NonNull MultiModelLoaderFactory multiFactory);

    /**
     * A lifecycle method that will be called when this factory is about to replaced.
     */
    void teardown();
}
